"use strict";
cc._RF.push(module, '1d55abboT5BIJjnZ/fCdLH7', 'GbzBox');
// scripts/game/GbzBox.ts

"use strict";
// carolsail
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GbzResManager_1 = require("../manager/GbzResManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GbzBox = /** @class */ (function (_super) {
    __extends(GbzBox, _super);
    function GbzBox() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.index = 0;
        _this.screwNum = 0;
        _this.screwNumMax = 3;
        return _this;
    }
    GbzBox.prototype.refresh = function (index) {
        var _this = this;
        this.index = index;
        this.node.getComponent(cc.Sprite).spriteFrame = GbzResManager_1.default.ins.sprite("gbz_box" + index);
        var screwNode = this.node.getChildByName('screws');
        screwNode.children.forEach(function (screw, i) {
            screw.getComponent(cc.Sprite).spriteFrame = GbzResManager_1.default.ins.sprite("gbz_screw" + index);
            screw.active = i < _this.screwNum;
        });
    };
    GbzBox.prototype.isActive = function () {
        var active = true;
        var isLock = (Boolean)(this.node.getChildByName('lock'));
        var isScale = this.node.scale < 1;
        if (isLock || isScale || this.screwNum >= this.screwNumMax)
            active = false;
        return active;
    };
    GbzBox.prototype.isLock = function () {
        return (Boolean)(this.node.getChildByName('lock'));
    };
    GbzBox.prototype.unlock = function () {
        if (this.node.getChildByName('lock'))
            this.node.getChildByName('lock').removeFromParent(true);
    };
    GbzBox.prototype.addScrewNum = function () {
        this.screwNum += 1;
    };
    GbzBox.prototype.setScrewNum = function (num) {
        this.screwNum = num;
    };
    GbzBox.prototype.checkFull = function () {
        var isFull = false;
        if (this.screwNum >= this.screwNumMax) {
            var screwNode = this.node.getChildByName('screws');
            var index = screwNode.children.findIndex(function (screw) { return !screw.active; });
            if (index < 0)
                isFull = true;
        }
        return isFull;
    };
    GbzBox.prototype.getScrewCurrent = function () {
        var screwNode = this.node.getChildByName('screws');
        var screw = screwNode.children[this.screwNum];
        return screw;
    };
    GbzBox = __decorate([
        ccclass
    ], GbzBox);
    return GbzBox;
}(cc.Component));
exports.default = GbzBox;

cc._RF.pop();